import Vue from 'vue'; // 导入vue模块
import VueRouter from 'vue-router'; // 导入vue-router模块
// import Home from '../views/Home.vue' //导入Home单文件组件  '上文'

// import Admin from '../views/admin/index.vue'
import Test from '@/views/Test.vue';
import Welcome from '@/views/Welcome.vue';
import Layout from '@/layout/Index.vue';
import UsersHistory from '@/views/users/History.vue';
import Users from '@/views/users/Index.vue';
import Roles from '@/views/roles/Index.vue';
import Auths from '@/views/auths/Index.vue';
import AuthsCreate from '@/views/auths/Create.vue';

import UsersCreate from '@/views/users/Create.vue';
import RolesCreate from '@/views/roles/Create.vue';
Vue.use(VueRouter);

// 重写底层代码,捕捉错误
// const originalPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch((err) => err);
// };

const routes = [
  // {path,name,component,alias,redirect,meta,children}
  // 导入可以使用"上文"的方式,也可以使用下文的方式
  {
    path: '/',
    component: Layout,
    // 声明子组件
    children: [
      {
        path: 'welcome',
        alias: '/',
        component: Welcome
      },
      {
        path: 'users/history',
        component: UsersHistory
      },
      {
        path: 'users',
        component: Users
      },
      {
        path: 'test',
        component: Test
      },
      {
        path: 'users/create',
        component: UsersCreate
      },
      {
        path: 'roles',
        component: Roles
      },
      {
        path: 'roles/create',
        component: RolesCreate
      },
      {
        path: 'auths',
        component: Auths
      },
      {
        path: 'auths/create',
        component: AuthsCreate
      }
    ]
  },
  // {
  //     path: '/',
  //     name: 'Home',
  //     component: Home
  // },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.

    // '下文'
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
];

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

export default router;
